﻿#ifndef DASYSTEMINFO_H
#define DASYSTEMINFO_H

#include <QString>
#include <QLabel>
#include <QTimer>
#include <QWidget>
#include <QPaintEvent>
#include <QPieSeries>
#include <QChartView>
#include <QLineSeries>


#if (QT_VERSION_MAJOR==5)
//Qt5 需要引入QChart命名空间，或者加上作用域，qt6不需要
QT_CHARTS_USE_NAMESPACE

#endif

#define CPULineSeries 0

class DASystemInfo : public QWidget
{
    Q_OBJECT
public:
    explicit DASystemInfo(QWidget *parent = nullptr);

    enum RateUnit {
        RateBit,
        RateByte,
        RateKb,
        RateMb,
        RateGb,
        RateTb,
        RateUnknow
    };
    Q_ENUM(RateUnit)

    enum Sensitive {
        Default,  // 大小写混合
        Upper,    // 全部大写
        Lower     // 全部小写
    };

    QString getCpuUsed();
    QString getMemUsed();
    void getNetUploadDownload();
    double getSysInfoCpuRate();
    double getSysInfoMemRate();
    void MemChart(double memoryUsed);
    void CpuChart(double cpuLoadAverage);

    void StringModel();
    void ChartModel();
signals:

private:
    QTimer *timer;
    long old_cpuAll = 0;
    long old_cpuFree = 0;
    long old_upload = 0;
    long old_download = 0;
    QLabel LabelMem,LabelCPU,LabelUpload,LabelDownload;
    QLabel MemRate,CPURate,UploadRate,DownloadRate;
    QString setRateUnitSensitive(DASystemInfo::RateUnit unit, DASystemInfo::Sensitive sensitive);
    double autoRateUnits(long speed, DASystemInfo::RateUnit &unit);
    void paintEvent(QPaintEvent *e);

    QPieSeries *mSeries;
#if CPULineSeries
    QLineSeries *cSeries;
    
#else
    QPieSeries *cSeries;
    QLabel *cRate;
#endif
    QChartView *mChartView,*cChartView;
    QLabel *mRate;
    int mPointPositionX = 0;
};

#endif // DASYSTEMINFO_H
